/****** Object:  Stored Procedure dbo.CGO_PaymentSave    Script Date: Thursday, March 24, 2011 ******/
IF EXISTS ( SELECT  *
            FROM    dbo.sysobjects
            WHERE   id = OBJECT_ID(N'dbo.CGO_PaymentSave')
                    AND OBJECTPROPERTY(id, N'IsProcedure') = 1 ) 
  DROP PROCEDURE dbo.CGO_PaymentSave
GO

/* -------------------------------------------------------------------------------------
/   PaymentUpdate
/  ------------------------------------------------------------------------------------- */
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE dbo.CGO_PaymentSave
  @PaymentID INT ,
  @PortalID INT ,
  @UserID INT ,
  @Amount MONEY ,
  @StatusID INT ,
  @EnrollmentID INT
AS 
  DECLARE @RetPaymentID INT
  SET @RetPaymentID = 0
  
  IF @EnrollmentID = 0
  BEGIN
  	SET @EnrollmentID = NULL
  END
  
  IF @PaymentID IS NOT NULL AND @PaymentID > 0
  BEGIN
    UPDATE  dbo.CGO_Payment
    SET     StatusID = @StatusID ,
            LastUpdateDate = GETDATE()
    WHERE   PortalID = @PortalID
            AND PaymentID = @PaymentID		

    SET @RetPaymentID = @PaymentID           
  END
  ELSE 
  BEGIN
    INSERT  INTO dbo.CGO_Payment
            ( PortalID ,
              UserID ,
              Amount ,
              StatusID ,
              EnrollmentID , 
              CreatedDate ,
              LastUpdateDate
            )
    VALUES  ( @PortalID ,
              @UserID ,
              @Amount ,
              @StatusID ,
              @EnrollmentID ,
              GETDATE() ,
              GETDATE()
            )
    SET @RetPaymentID = @@IDENTITY
  END
  
  SELECT @RetPaymentID
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
